package com.steven.sync;


import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * :
 */
public class CountDownLatch_test {

    private static Thread[] threads = new Thread[10];
    private static CountDownLatch countDownLatch = new CountDownLatch(threads.length);

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < threads.length; i++) {
            TimeUnit.SECONDS.sleep(1);
            System.out.println(Thread.currentThread().getName());
            threads[i] = new Thread(() -> countDownLatch.countDown());
        }

        for (int i = 0; i <threads.length; i++) {
            threads[i].start();
        }

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("下车");
    }

}
